var data = {terdakwa: []};

(function($) {
	$(document).ready(function(e) {
		$("#da-tgl-penyidikan").datepicker({dateFormat: "dd-mm-yy"});
		$("#da-tgl-diterima").datepicker({dateFormat: "dd-mm-yy"});
		
		$( "#spdp_melanggar_pasal" ).change(function() {
			var arrSplit = $("#spdp_melanggar_pasal").val().split(" ");
			if(arrSplit.length >= 2){
				if($.isNumeric(arrSplit[0])){
					if(parseInt(arrSplit[0])>0 && parseInt(arrSplit[0])<=303){
						$( "#spdp_kd_pidana" ).val(1);
					}else if(parseInt(arrSplit[0])>0){
						$( "#spdp_kd_pidana" ).val(2);
					}
				}else{
					$( "#spdp_kd_pidana" ).val(3);
				}
			}else if((arrSplit.length >0)){
				$( "#spdp_kd_pidana" ).val(3);
			}
		});

		
		$.fn.select2 && $(".select").select2();
		
		if($.fn.validate) {
			$("#da-form-spdp").validate({
				ignore: '.ignore', 
				rules: {
					no_polisi: {
						required: true
					}, 
					tgl_penyidikan: {
						required: true
					}, 
					kd_kesatuan: {
						required: true
					}, 
					melanggar_pasal: {
						required: true
					}, 
					kd_pidana: {
						required: true
					}, 
					tgl_diterima: {
						required: true
					}
				}
			});
		}
		
		$("#da-ex-dialog-form-div").dialog({
			autoOpen: false, 
			title: "Tambah Tersangka", 
			modal: true, 
			width: "800", 
			//height: "600", 
			buttons: [{
					text: "Submit", 
					click: function() {
						$( this ).find('form#da-ex-dialog-form-val').submit();
						$( this ).dialog( "close" );
					}}]
		}).find('form').validate({
			rules: {
				nama: {
					required: true
				}, 
				tmp_lahir: {
					required: true
				}, 
				jns_kelamin: {
					required: true
				}, 
				warganegara: {
					required: true
				}, 
				alamat: {
					required: true
				},
				pekerjaan: {
					required: true
				}
			}
		});
		
		$("#da-ex-dialog-form").bind("click", function(event) {
			$("#da-ex-dialog-form-div").dialog("option", {modal: true}).dialog("open");
			event.preventDefault();
		});
		$("#tambah-tersangka").bind("click", function(event) {
			$('#mode-input').attr({
				name: 'tambah',
				value: 'tersangka'
			});
		});
	});
}) (jQuery);
